import React from 'react';

import { ChangePassword } from '@/entities/auth/ui/ChangePassword';
import { ConfirmExitModal } from '@/entities/auth/ui/ConfirmExitModal';
import { GetNewPassword } from '@/entities/auth/ui/GetNewPassword';
import { SuccessPassword } from '@/entities/auth/ui/SuccessPassword';
import { CreateOrderModal } from '@/entities/course/ui/CreateOrderModal';
import { SuccessModal } from '@/entities/course/ui/SuccessOrderModal';
import { AdvantagesModal } from '@/entities/profile/ui/Advantages';
import { ChangeTarif } from '@/entities/profile/ui/ChangeTarif';
import { DeletePaymentCard } from '@/entities/profile/ui/DeletePaymentCard';
import { DeleteProfile } from '@/entities/profile/ui/DeleteProfile';
import { EditAvatar } from '@/entities/profile/ui/EditAvatar';
import { PremiumWelcome } from '@/entities/profile/ui/PremiumWelcome';
import { Subscription } from '@/entities/profile/ui/Subscription';
import { TarifPlans } from '@/entities/profile/ui/TarifPlans';
import { TurnOffPremium } from '@/entities/profile/ui/TurnOffPremium';
import { ConfirmDelete } from '@/entities/rating/ui/ConfirmDelete';
import { RatingSendModal } from '@/entities/rating/ui/RatingSendModal';
import { SendReviewModal } from '@/entities/rating/ui/SendReviewModal/SendReviewModal';
import { AddPaymentCard } from '@/features/AddPaymentCard/modal/AddPaymentCard';
import { ShareModal } from '@/features/Share/ui/modal';
import { ConfirmSendModal } from '@/widgets/feedback/ConfirmSendModal';
import { FeedbackModal } from '@/widgets/feedback/Feedback';
import { MessageSendModal } from '@/widgets/feedback/MessageSendModal';

import { Modals } from '../interfaces';

const createModal = <S extends string, P extends ModalProps>(id: S, Component: React.FC<P>) =>
  ({
    id,
    Component,
  } as const);

export const modals = {
  CreateOrderModal: createModal(Modals.CreateOrderModal, CreateOrderModal),
  GetNewPassword: createModal(Modals.GetNewPassword, GetNewPassword),
  SuccessPassword: createModal(Modals.SuccessPassword, SuccessPassword),
  SuccessModal: createModal(Modals.SuccessModal, SuccessModal),
  RatingSendModal: createModal(Modals.RatingSendModal, RatingSendModal),
  ShareModal: createModal(Modals.ShareModal, ShareModal),
  FeedbackModal: createModal(Modals.FeedbackModal, FeedbackModal),
  EditAvatar: createModal(Modals.EditAvatar, EditAvatar),
  MessageSendModal: createModal(Modals.MessageSendModal, MessageSendModal),
  ConfirmModal: createModal(Modals.ConfirmModal, ConfirmSendModal),
  ConfirmExitModal: createModal(Modals.ConfirmExitModal, ConfirmExitModal),
  ConfirmDelete: createModal(Modals.ConfirmDelete, ConfirmDelete),
  SendReview: createModal(Modals.SendReview, SendReviewModal),
  ChangePassword: createModal(Modals.ChangePassword, ChangePassword),
  DeleteProfile: createModal(Modals.DeleteProfile, DeleteProfile),
  AdvantagesModal: createModal(Modals.AdvantagesModal, AdvantagesModal),
  ChangeTarif: createModal(Modals.ChangeTarif, ChangeTarif),
  TarifPlans: createModal(Modals.TarifPlans, TarifPlans),
  AddPaymentCard: createModal(Modals.AddPaymentCard, AddPaymentCard),
  DeletePaymentCard: createModal(Modals.DeletePaymentCard, DeletePaymentCard),
  PremiumWelcome: createModal(Modals.PremiumWelcome, PremiumWelcome),
  TurnOffPremium: createModal(Modals.TurnOffPremium, TurnOffPremium),
  Subscription: createModal(Modals.Subscription, Subscription),
};

export const modalsComponentsMap = Object.values(modals).reduce(
  (res, { id, Component }) => ({ ...res, [id]: Component }),
  {} as Record<ModalId, Component>,
);

type Modal = (typeof modals)[keyof typeof modals];
export type ModalId = Modal['id'];
type Component = Modal['Component'];

export interface ModalProps {
  onClose: () => void;
  data?: any;
}
